import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { HydratedDocument } from 'mongoose';

export type UserDocument = HydratedDocument<User>;

@Schema({
  timestamps: true,
  toJSON: {
    transform(doc, ret) {
      delete ret.password;
      delete ret.__v;
    },
  },
})
export class User {
  //   手机号，邮箱，或者是
  // Oauth Provider + ID，eg：Gitee123456
  @Prop({ required: true, unique: true })
  username: string;

  // 加密存储。只有邮箱注册登录的时候是需要的
  @Prop()
  password?: string;

  @Prop()
  nickName?: string;

  // 头像图片 url
  @Prop()
  picture?: string;

  @Prop()
  phoneNumber?: string;

  @Prop()
  city?: string;

  // 账户类型（邮箱，手机 oatuh）
  @Prop({ enum: ['email', 'cellphone', 'oauth'] })
  type?: string;

  // oauth 提供方
  @Prop({ enum: ['gitee', 'guthub', 'weixin'] })
  provider?: string;

  @Prop()
  oauthID?: string;

  //   @Prop()
  //   createdAt: Date;
  //   @Prop()
  //   updatedAt: Date;
}

export const UserSchema = SchemaFactory.createForClass(User);
